# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 12:18
# @Author  : Alvin
# @File    : app.py
from flask.json.provider import DefaultJSONProvider as _DefaultJSONProvider
from app.libs.error_code import ServerError
from datetime import date
from flask import Flask as _Flask

class DefaultJSONProvider(_DefaultJSONProvider):
    def default(self, o):
        if hasattr(o, 'keys') and hasattr(o, '__getitem__'):
            return dict(o)
        if isinstance(o, date):
            # 格式化时间
            return o.strftime('%Y-%m-%d')
        raise ServerError()
class Flask(_Flask):
    json_provider_class = DefaultJSONProvider
